EFFECT.Exp = {}
EFFECT.Exp[1] = Sound("ambient/explosions/explode_4.wav")
EFFECT.Exp[2] = Sound("ambient/explosions/explode_9.wav")

function EFFECT:Init(data)
	
	self.Heirach = data:GetEntity()
	self.Entity:SetPos(data:GetOrigin())
	self.Origin = data:GetOrigin()
	self.Color = Color(data:GetStart().x, data:GetStart().y, data:GetStart().z, 255)
	self.Size = data:GetRadius()
	self.Normal = data:GetNormal()
	
	if (self.Heirach != NULL) and (self.Heirach:IsValid()) then
		self.Entity:SetParent(self.Heirach)
		self.Velocity = self.Heirach:GetVelocity()
	end
	
	self.LifeTime = data:GetMagnitude()
	self.StartTime = CurTime()
	
	
	self.particles = {}
	
	self.Entity:SetPos(self.Origin)
	
	WorldSound(self.Exp[math.random(1,2)], self.Origin, 100, 100)
	--self.Velocity = self.Prop:GetPhysicsObject():GetVelocity()
	
		local emitter = ParticleEmitter(self.Entity:GetPos())
		for i=1,20 do
			local particle = emitter:Add("Sprites/glow01", self.Entity:GetPos())
			particle:SetColor(255, 140, 0, 255)
			particle:SetVelocity((self.Normal * self.Size) + (self.Entity:RndNormalVector() * (self.Size * 0.8)))
			particle:SetDieTime(self.LifeTime * 2)
			particle:SetLifeTime(math.Rand(0, self.LifeTime))
			particle:SetStartSize(math.Rand(0, self.Size/2))
			particle:SetEndSize(0)
			particle:SetStartAlpha(255)
			particle:SetEndAlpha(0)
		end
		
		local detonator = ParticleEmitter(self.Entity:GetPos())
		for i=1,5 do
			local particle = detonator:Add("particles/flamelet" .. math.random(1,5), self.Entity:GetPos())
			particle:SetColor(255, 140, 0, 255)
			particle:SetVelocity(Vector(0, 0, 0))
			particle:SetDieTime(self.LifeTime)
			particle:SetLifeTime(0)
			particle:SetStartSize(math.Rand(self.Size / 2, self.Size))
			particle:SetEndSize(self.Size)
			particle:SetStartAlpha(255)
			particle:SetEndAlpha(0)
			table.insert(self.particles, particle)
		end
end

function EFFECT:RndNormalVector()
	local Vect = Vector()
	Vect.x = math.Rand(-1,1)
	Vect.y = math.Rand(-1,1)
	Vect.z = math.Rand(-1,1)
	return Vect
end

function EFFECT:Think()
	if ((self.StartTime + self.LifeTime) < CurTime()) then
		return false
	else
		return true
	end
end

function EFFECT:Render()
	for _,particle in pairs(self.particles) do
		particle:SetPos(self.Entity:GetPos())
	end
end
